<%var body = {%>
<form method="post" class="eova-form" onsubmit="return false;" style="background-color: white">

	<input type="hidden" name="parent_id" value="${parent_id!0}">

	<fieldset>
        <legend>流程基础信息</legend>
		<div class="eova-form-field">
			<label class="eova-form-label red">流程名称</label>
			<#text id="name" name="name" value="" />
		</div>
		<div class="eova-form-field">
			<label class="eova-form-label red">流程编码</label>
			<#text id="code" name="code" value="" />
		</div>
	</fieldset>
	<fieldset>
		<legend>流程设计</legend>
		<div class="eova-form-field">
			<label class="eova-form-label red">流程元对象</label>
			<#find id="object_code" name="object_code" code="eova_field_code" field="object_code" />
		</div>
		<div class="eova-form-field">
			<label class="eova-form-label red">流程状态字段</label>
			<#find id="object_field" name="object_field"/>
		</div>
		<div class="eova-form-field">
			<label class="eova-form-label red">流程设计命令</label>
			<#texts id="details" name="bs" placeholder="请手写命令或通过功能添加命令\n菜单名|菜单编码|过滤的状态值|授权角色ID" style="width:530px;height:200px;" />
		</div>
	</fieldset>
	<fieldset>
        <legend>流程设计-命令生成</legend>
		<div class="eova-form-field">
			<label class="eova-form-label">菜单名称</label>
			<#text id="menu_name" name="menu_name" value="" placeholder="菜单名称必须唯一" />
		</div>
		<div class="eova-form-field">
			<label class="eova-form-label">菜单编码</label>
			<#text id="menu_code" name="menu_code" value="" placeholder="菜单编码必须唯一" />
		</div>
		<div class="eova-form-field" title="可多选">
			<label class="eova-form-label">显示状态</label>
			<#combo id="menu_show_status" name="menu_show_status" multiple="true" />
		</div>
		<div class="eova-form-field" title="可多选">
			<label class="eova-form-label">授权给角色</label>
			<#combo id="btn_role" name="role" exp="selectEovaRole" multiple="true" value="1" />
		</div>
	</fieldset>
</form>
<div class="layui-layer-btn layui-layer-btn-c">
	<button class="layui-btn layui-btn-danger layui-btn-sm" id="addMenu">
		<i class="layui-icon eova-icon-add-1"></i>添加命令
	</button>
</div>

<script type="text/javascript">

	$(document).ready(function(){
		var $object = $('#object_code');
	    var $field= $('#object_field');
	    var $menu_show_status= $('#menu_show_status');
	    
	    // 生成菜单命令
	    $('#addMenu').click(function(){
	    	var p1 = $('#menu_name').eovatext().getValue();
	    	var p2 = $('#menu_code').eovatext().getValue();
	    	var p3 = $('#menu_show_status').eovacombo().getValues();
	    	var p4 = $('#btn_role').eovacombo().getValues();
	    	if(p1 == ''){
	    		$.msg('菜单名称必填');
	    		return;
	    	}
	    	if(p2 == ''){
	    		$.msg('菜单编码必填');
	    		return;
	    	}
	    	if(p3 == ''){
	    		$.msg('显示状态必选');
	    		return;
	    	}
	    	if(p4 == ''){
	    		$.msg('授权给角色必选');
	    		return;
	    	}
	    	$('#details').val($('#details').val() + $.str.format('{0}|{1}|{2}|{3};\n', p1, p2, p3, p4));
	    	$('#menu_name').eovatext().setValue("");
	    	$('#menu_code').eovatext().setValue("");
	    	$('#menu_show_status').eovacombo().setValues("");
	    	$('#btn_role').eovacombo().setValues(1);
	    });
	
	    var findField = $field.eovafind();
	    var menu_show_status = $menu_show_status.eovacombo();
	    
	    findField.readonly(true);
	    menu_show_status.readonly(true);
	
	    $object.eovafind({onChange: function (oldValue, newValue) {
	    	findField.setValue("");
	    	menu_show_status.setValue("");
	
	        if (newValue == "") {
	        	findField.readonly(true);
	            return;
	        }
	        findField.readonly(false);
	        
	        $field.eovafind({exp : 'selectEovaFieldByObjectCode,' + newValue});
	    }});
	    
	    $field.eovafind({onChange: function (oldValue, newValue) {
	    	menu_show_status.setValue("");
	
	        if (newValue == "") {
	        	menu_show_status.readonly(true);
	            return;
	        }
	        menu_show_status.readonly(false);
	        
	        // 动态获取字段的表达式
	        $.syncGetJson($.str.format("/meta/dicts/{0}-{1}", $object.eovafind().getValue(), findField.getValue()), function(o){
	        	$menu_show_status.eovacombo({json : o}).reload();
	        })
	    }});
	    
	});

    $(function () {
    	$.configValidator($form, {
	        name: {rule: '流程名称:required;'},
	        code: {rule: '流程编码:required;'},
	        object_code: {rule: '流程元对象:required;'},
	        object_field: {rule: '流程状态字段:required;'},
	        details: {rule: '流程设计命令:required;'},
    	});
        
        $('.template').click(function(){
        	$('#ui').eovatext().setValue($(this).data('ui'));
        	var txt = $(this).text();
        	var $uiuri = $('#ui_uri');
        	if(txt == '自定义'){
        		$uiuri.hide();
        		$form.validator("setField", "uri", null);
        	} else {
        		$uiuri.show();
        		$form.validator("setField", "uri", "服务端URL:required;");
        	}
        	
        	return false;
        })
    });
</script>

<script type="text/javascript">
// ------------------------- 动态参数配置
var $form = $('.eova-form');
var action = '/menu/doFlow';
var msg = '添加按钮成功';
// ------------------------- 动态参数配置

// 确认按钮回调
var btnSaveCallback = function($dialog, ID, $$) {
	submitForm($$, ID, $form, action, msg);
};

layui.use(['table', 'element'], function() {
	var $ = layui.$,
	table = layui.table,
	element = layui.element;
});
</script>

<%};include("/eova/layout/form.html",{'title' : '快速添加按钮', 'layoutContent' : body, 'isEditor' : false}){}%>